package com.dayangxiaoen.controller;

import com.alibaba.fastjson.JSON;
import com.dayangxiaoen.pojo.ItemReduce;
import com.dayangxiaoen.pojo.ItemReduceShow;
import com.dayangxiaoen.vo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.LinkedList;
import java.util.List;

/**
 * @author dayangxiaoen
 */

@RestController
@RequestMapping("bilibili")
@Slf4j
public class ItemsController {

    @Autowired
    private RedisTemplate<String,String> redisTemplate;

    @GetMapping("lists")
    public Result findAllProducts(){

        int count = 1;

        LinkedList<ItemReduceShow> list = new LinkedList<ItemReduceShow>();

        String itemJson = null;

        while((itemJson = redisTemplate.opsForValue().get("fufu"+count))!=null){
            ItemReduce itemReduce = JSON.parseObject(itemJson, ItemReduce.class);


            ItemReduceShow itemReduceShow = new ItemReduceShow();
            itemReduceShow.setName(itemReduce.getName());
            itemReduceShow.setId("fufu"+count);
            itemReduceShow.setShowPrice(itemReduce.getShowPrice());
            itemReduceShow.setShowMarketPrice(itemReduce.getShowMarketPrice());
            list.add(itemReduceShow);

            count ++;
        }

        return Result.sucess(list,"获取到部分芙芙手办信息");
    }

}
